1. Field of the Invention
This invention relates generally to processing of three-dimensional computer graphics, and more particularly, to the blending of true colors and fog colors to produce display colors.
2. Description of the Related Art
As a result of advances in technology there is an increasing demand for realistic three-dimensional computer graphics and video. Fogging is the phenomenon in which objects become blurry and fuzzy and appear to fade in color as the distance between the object and viewer increases. It is desirable to simulate fogging in order to render realistic three-dimensional graphics.
Fogging typically is implemented in the following manner. Each object or pixel to be rendered has a true color and a fog color. The true color is the color which the object would appear if it were close to the viewer. The fog color is the color which the object would appear if it were far away from the viewer. For example, the true color of a carrot might be orange; while the corresponding fog color might be gray. A fog function describes the manner in which the actual displayed color varies from the true color to the fog color as the distance between viewer and object increases.
To calculate the proper display color for an object, a graphics accelerator typically receives the true color, the fog color, and the distant z from the object to the viewer. The accelerator calculates the value of the fog function for the distance z and then blends the true color and the fog color accordingly to arrive at the display color.
The fog function is typically calculated by interpolation. In one approach, sampled values of the fog function are stored in a memory which only has a single output port (xe2x80x9csingle-port memoryxe2x80x9d) and so can only support one read per clock cycle. However, at least two values are required to interpolate the fog function so at least two cycles are required to read out the required sampled values. This is slow. In another approach, the sampled values may be stored in a memory with multiple output ports thus allowing multiple reads in a single cycle. In this case, the required sampled values may be read out in a single clock cycle. This type of memory, however, is typically more expensive.
Hence, there is a need for a device which interpolates a fog function by reading the required sampled values of the fog function in a single clock cycle, but which only uses single-port memory.
In accordance with the present invention, a device for calculating a display color based on a true color, a fog color, and a distance z preferably includes an index generator, two memories, an arithmetic circuit, and a color blending circuit. The index generator receives the distance z and generates two memory addresses, one for each memory. Two sampled values of a fog function are read from the memories according to the memory addresses. The arithmetic circuit receives the sampled values of the fog function and calculates an approximate value of the fog function which corresponds to the distance z. The arithmetic circuit preferably calculates the approximate value by linearly interpolating between the two sampled values. The color blending circuit then calculates the display color by blending the true color and the fog color according to the approximate value of the fog function.
In further accordance with the present invention, a method for calculating a display color based on a true color, a fog color, and a distance z includes the following steps. The distance z, the true color, and the fog color are received. Two memory addresses are generated responsive to the distance z. Two sampled values of a fog function are read from two memories according to the memory addresses, one from each memory. An approximate value of the fog function corresponding to the distance z is calculated based on the two sampled values of the fog function. The display color is then calculated by blending the true color and the fog color according to the approximate value of the fog function.